$(document).ready(function () {
    GetRequestData(GetRequest())
});

function GetRequestData(list){
    if(JSON.stringify(list) != "{}"){
        // console.log(list['id'])
        $("#searchInput").val(list['id']);
        getData(list['id'])
    }
}

function getData(id){
    // console.log(id)
    $.ajax({
        url: global.apiUrl + '/get_user_fatdata',
        type: 'GET',
        dataType: 'json',
        data: {
            id: id,
        },
        header: {
            'content-type': 'application/json' //默认值
        },
        success: function(res){
            // console.log(res)
            if(res.content!=0){
                var list = res.content[0]
                var title = '';
                title += `<div class="titleItem">
                            <text>${list.nickname}</text>
                            <text>${list.sex}</text>
                            <text>${list.height}cm</text>
                            <text>ID: ${list.user_id}</text>
                        </div>
                        <text style="margin-right: 20px">时间：${list.createtime}</text>`
                $('#titleAre').html(title)
                var html = '';
                var arr =  list.content.bz.concat(list.content.height).concat(list.content.low)
                // console.log(arr)
                for(var i in arr){
                    html += `<div class="detailsItemAre">
                                <div class="detailsItemMainAre">
                                    <div class="detailsItem">
                                        <div class="detailsTitle">
                                            <text style="font-size:18px">${arr[i].title}：${arr[i].value}${setUnit(arr[i].title)}</text>
                                            <text class="subtitle">${setSubtitle(arr[i].title)}</text>
                                        </div>
                                        <div class="detailsTipAre">
                                            <div class="tipAre" style="background: ${getTipColor(arr[i].type)}">${arr[i].type}</div>
                                            <div class="glyphicon glyphicon-menu-down"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="detailsItemIntervalAre">
                                    <div class="MeasuringRangeAre">
                                        ${setInterval(arr[i].title,arr[i].best)}
                                    </div>
                                    <div class="MeasuringRangeText">
                                        <text >
                                            &emsp;&emsp;${setIntroduce(arr[i])}
                                        </text>
                                    </div>
                                </div>
                            </div>`
                }
                $('#details').html(html)
            }
            
        }
    })
}

$('#details').on("click",".detailsItemMainAre",function(){
    if($(this).next().css('display') == 'none'){
        $(this).find('.glyphicon').removeClass('glyphicon-menu-down').addClass('glyphicon-menu-up')
        $(this).next().css('display','block');
    }else{
        $(this).find('.glyphicon').removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down')
        $(this).next().css('display','none')
    }
})

function setSubtitle(name){
    var subtitle = ''
    switch (name) {
        case '体重':
            subtitle: '人体总重量'
            break;
        case 'BMI':
            subtitle: '衡量人体肥胖程度和健康标准'
            break;
        case '基础代谢':
            subtitle: '人体基本的能量代谢指'
            break;
        case '骨量':
            subtitle: '人体骨骼矿物质的总和'
            break;
        case '肌肉量':
            subtitle: '人体骨骼肌、平滑肌等肌肉含量'
            break;
        case '内脏脂肪':
            subtitle: '腹腔内所有的脏器上附着的脂肪含量'
            break;
        case '水分率':
            subtitle: '体内液体总量占体重的百分比'
            break;
        case '体脂率':
            subtitle: '人体皮下脂肪含量'
            break;
        case '蛋白质率':
            subtitle: '人体总蛋白质'
            break;
        case '体年龄':
            subtitle: '人体基础代谢的年龄倾向'
            break;
    }
    return subtitle
}
